﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfApp1.Models;
using WpfApp1.Utils;

namespace WpfApp1.ViewModels
{
    public class TestViewModel : ObservableObject
    {
        public RelayCommand ShowInfoMsg { get; set; }
        public RelayCommand ShowSuccessMsg { get; set; }
        public RelayCommand ShowWarnMsg { get; set; }
        public RelayCommand ShowErrorMsg { get; set; }
        public RelayCommand ShowFatalMsg { get; set; }

        public RelayCommand AskMsg { get; set; }


        public RelayCommand ShowInfoGlobalMsg { get; set; }
        public RelayCommand ShowSuccessGlobalMsg { get; set; }
        public RelayCommand ShowWarnGlobalMsg { get; set; }
        public RelayCommand ShowErrorGlobalMsg { get; set; }
        public RelayCommand ShowFatalGlobalMsg { get; set; }

        public RelayCommand AskGlobalMsg { get; set; }

        public RelayCommand CleanAll { get; set; }

        public RelayCommand ErrorNull { get; set; }
        public RelayCommand ErrorTask { get; set; }

        public RelayCommand ErrorReadNull { get; set; }

        public List<int> Errors { get; set; }

        public TestViewModel()
        {
            ShowInfoMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Info", MsgHelper.MsgType.Info);
            });
            ShowSuccessMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Success", MsgHelper.MsgType.Success);
            });
            ShowWarnMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Warn", MsgHelper.MsgType.Warn);
            });
            ShowErrorMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Error", MsgHelper.MsgType.Error);
            });
            ShowFatalMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Fatal", MsgHelper.MsgType.Fatal);
            });

            CleanAll = new RelayCommand(() => { MsgHelper.CleanAll(); });

            AskMsg = new RelayCommand(() =>
            {
                MsgHelper.Ask("本地询问", (isConfrim) =>
                {
                    MsgHelper.ShowMsg($"本地询问结果[{isConfrim}]", MsgHelper.MsgType.Info);
                });
            });


            ShowInfoGlobalMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Info", MsgHelper.MsgType.Info, true);
            });
            ShowSuccessGlobalMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Success", MsgHelper.MsgType.Success, true);
            });
            ShowWarnGlobalMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Warn", MsgHelper.MsgType.Warn, true);
            });
            ShowErrorGlobalMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Error", MsgHelper.MsgType.Error, true);
            });
            ShowFatalGlobalMsg = new RelayCommand(() =>
            {
                MsgHelper.ShowMsg("Fatal", MsgHelper.MsgType.Fatal, true);
            });


            AskGlobalMsg = new RelayCommand(() =>
            {
                MsgHelper.Ask("全局询问", (isConfrim) =>
                {
                    MsgHelper.ShowMsg($"全局询问结果[{isConfrim}]", MsgHelper.MsgType.Info, true);
                }, true);
            });

            ErrorNull = new RelayCommand(() =>
            {
                Errors.Add(0);
            });

            ErrorReadNull = new RelayCommand(() =>
            {
                var res = File.ReadAllLines("读取文件");
            });

            ErrorTask = new RelayCommand(() =>
            {
                Task.Run(() =>
                {
                    Errors.Add(0);

                });
            });

        }
    }
}
